package com.example.mybatisplus.web.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.mybatisplus.common.utls.SessionUtils;
import com.example.mybatisplus.model.dto.DeleteDTO;
import com.example.mybatisplus.model.dto.PageDTO;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.stereotype.Controller;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.example.mybatisplus.common.JsonResponse;
import com.example.mybatisplus.service.WhitelistSettingService;
import com.example.mybatisplus.model.domain.WhitelistSetting;

import javax.servlet.http.HttpServletResponse;


@RestController
@RequestMapping("/api/whitelistSetting")
public class WhitelistSettingController {

    @Autowired
    private WhitelistSettingService whitelistSettingService;

    @PostMapping("login")
    public JsonResponse login(@RequestBody WhitelistSetting whitelistSetting){
        WhitelistSetting user =whitelistSettingService.login(whitelistSetting);
        return JsonResponse.success(user);
    }
    @GetMapping("logout")
    public JsonResponse logout(){
        SessionUtils.clearCurUser();
        return JsonResponse.success(true);
    }
    @GetMapping("pageList")
    public JsonResponse pageList(WhitelistSetting whitelistSetting, PageDTO dto){
        Page<WhitelistSetting> page=whitelistSettingService.pageList(whitelistSetting,dto);
        return JsonResponse.success(page);

    }
    //删除get
    @GetMapping("removeById")
    public JsonResponse removeById(Long id){
       boolean b= whitelistSettingService.removeById(id);
       return JsonResponse.success(b);
    }
//删除post
    @PostMapping("removeById2")
    public JsonResponse removeById(@ RequestBody WhitelistSetting whitelistSetting){

        boolean b= whitelistSettingService.removeById(whitelistSetting.getId());
        return JsonResponse.success(b);
    }
    @PostMapping("removeByIds")
    public JsonResponse removeByIds(@ RequestBody DeleteDTO dto){
//感觉会报错
        boolean b= whitelistSettingService.removeByIds(dto.getIds());
        return JsonResponse.success(b);
    }
    @PostMapping("edit")
    public JsonResponse edit(@RequestBody WhitelistSetting whitelistSetting){
       boolean b= whitelistSettingService.updateById(whitelistSetting);
        return JsonResponse.success(b);
    }
    //数据导出
    @PostMapping("exportUser")
    public void exportUser(HttpServletResponse response){
        whitelistSettingService.exportUser(response);
    }


}

